package 第五周;

/*
 * @author  YxinMiracle
 * @date  2022-05-01 10:55
 * @Gitee: https://gitee.com/yxinmiracle
 */

public class 二分查找 {

    public int search(int[] nums, int target) {
        int left = 0;
        int right = nums.length - 1;
        while (left <= right) {
            int min = (left + right) / 2;
            if (nums[min] == target){
                return min;
            }
            if (nums[min] < target){
                left ++;
            }else {
                right --;
            }
        }
        return -1;
    }

}
